﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WISD.CarFriend.Web.Admin.Utility;
using System.Text;

namespace WISD.CarFriend.Web.Admin
{
    public partial class Index : Utility.BasicPage
    {
        #region 字段
        private string m_SystemMenu;
        private string m_WebMenu;
        private string m_OAMenu;
        #endregion


        #region 属性
        /// <summary>
        /// 系统菜单
        /// </summary>
        public string SystemMenu
        {
            get { return m_SystemMenu; }
            set { m_SystemMenu = value; }
        }


        /// <summary>
        /// Web菜单
        /// </summary>
        public string WebMenu
        {
            get { return m_WebMenu; }
            set { m_WebMenu = value; }
        }


        /// <summary>
        /// OA菜单
        /// </summary>
        public string OAMenu
        {
            get { return m_OAMenu; }
            set { m_OAMenu = value; }
        }
        #endregion


        #region 事件
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            this.m_SystemMenu = this.GetSystemMenu();
            this.m_WebMenu = this.GetWebMenu();
            this.m_OAMenu = this.GetOAMenu();

            if (!Page.IsPostBack)
            {
                try
                {
                    lblUserName.Text = Session["UserName"].ToString().Trim() + "（" + Session["UserRole"].ToString().Trim() + "）";
                }
                catch
                { }
            }
        }


        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lbtnExit_Click(object sender, EventArgs e)
        {
            try
            {
                Session["UserID"] = null;
                Session["UserCode"] = null;
                Session["UserName"] = null;
                Session["UserType"] = null;
                Session["UserPermission"] = null;
                Session["UserRole"] = null;
                Core.ServerImpl.Instance.Logout(Context);
                Response.Redirect("Login.aspx");
            }
            catch
            { }
        }

        #endregion


        #region 方法
        /// <summary>
        /// 获取系统管理菜单
        /// </summary>
        /// <returns></returns>
        private string GetSystemMenu()
        {
            StringBuilder menu = new StringBuilder();

            if (this.IsPermission("UserManage"))
            {
                menu.Append(" <li><a href=\"Module/UserManage/UserList.aspx\" target=\"sysMain\">用户管理</a></li> ");
            }
            if (this.IsPermission("RoleManage"))
            {
                menu.Append(" <li><a href=\"Module/RoleManage/RoleList.aspx\" target=\"sysMain\">角色管理</a></li> ");
            }

            return menu.ToString();
        }


        /// <summary>
        /// 获取网站系统菜单
        /// </summary>
        /// <returns></returns>
        private string GetWebMenu()
        {
            StringBuilder menu = new StringBuilder();

            if (this.IsPermission("IntroductionManage"))
            {
                menu.Append(" <li><a href=\"Module/IntroductionManage/List.aspx\" target=\"sysMain\">页面导航管理</a></li> ");
            }

            if (this.IsPermission("InformationManage"))
            {
                menu.Append(" <li><a href=\"Module/InformationManage/List.aspx\" target=\"sysMain\">资讯管理</a></li> ");
            }

            if (this.IsPermission("EnterpriseUnionManage"))
            {
                menu.Append(" <li><a href=\"Module/EnterpriseUnionManage/List.aspx\" target=\"sysMain\">商家联盟管理</a></li> ");
            }

            if (this.IsPermission("FriendLinkManage"))
            {
                menu.Append(" <li><a href=\"Module/FriendLinkManage/List.aspx\" target=\"sysMain\">友情链接管理</a></li> ");
            }

            if (this.IsPermission("AdvertisementManage"))
            {
                menu.Append(" <li><a href=\"Module/AdvertisementManage/List.aspx\" target=\"sysMain\">广告管理</a></li> ");
            }

            if (this.IsPermission("MemberRegist"))
            {
                menu.Append(" <li><a href=\"Module/MemberRegist/List.aspx\" target=\"sysMain\">会员注册提示</a></li> ");
            }

            return menu.ToString();
        }


        /// <summary>
        /// 获取办公系统菜单
        /// </summary>
        /// <returns></returns>
        private string GetOAMenu()
        {
            StringBuilder menu = new StringBuilder();

            if (this.IsPermission("MemberManage"))
            {
                menu.Append(" <li><a href=\"OA/MemberManage/Member.aspx\" target=\"sysMain\">会员管理</a></li> ");
            }
            if (this.IsPermission("MemberCardManage"))
            {
                menu.Append(" <li><a href=\"OA/MemberCardManage/MemberCard.aspx\" target=\"sysMain\">会员卡管理</a></li> ");
            }
            if (this.IsPermission("RechargeManage"))
            {
                menu.Append(" <li><a href=\"OA/RechargeManage/Recharge.aspx\" target=\"sysMain\">会员卡充值</a></li> ");
            }
            if (this.IsPermission("ConsumeManage"))
            {
                menu.Append(" <li><a href=\"OA/ConsumeManage/Consume.aspx\" target=\"sysMain\">会员消费</a></li> ");
            }
            if (this.IsPermission("ConsumeQuery"))
            {
                menu.Append(" <li><a href=\"OA/ConsumeManage/ConsumeQuery.aspx\" target=\"sysMain\">消费查询</a></li> ");
            }
            if (this.IsPermission("ReturnVisitManage"))
            {
                menu.Append(" <li><a href=\"OA/ReturnVisitManage/ReturnVisit.aspx\" target=\"sysMain\">会员回访</a></li> ");
            }
            if (this.IsPermission("ComplaintManage"))
            {
                menu.Append(" <li><a href=\"OA/ComplaintManage/Complaint.aspx\" target=\"sysMain\">会员投诉</a></li> ");
            }
            if (this.IsPermission("SubstituteDrivingManage"))
            {
                menu.Append(" <li><a href=\"OA/SubstituteDrivingManage/SubstituteDriving.aspx\" target=\"sysMain\">酒后代驾</a></li> ");
            }
            if (this.IsPermission("EmployeeManage"))
            {
                menu.Append(" <li><a href=\"OA/EmployeeManage/EmployeeList.aspx\" target=\"sysMain\">人事管理</a></li> ");
            }
            if (this.IsPermission("MemberCardTypeManage"))
            {
                menu.Append(" <li><a href=\"OA/MemberCardTypeManage/MemberCardTypeList.aspx\" target=\"sysMain\">会员卡类型</a></li> ");
            }
            if (this.IsPermission("ShopManage"))
            {
                menu.Append(" <li><a href=\"OA/ShopManage/ShopList.aspx\" target=\"sysMain\">特约商户</a></li> ");
            }
            if (this.IsPermission("ParaManage"))
            {
                menu.Append(" <li><a href=\"OA/ParaManage/ParaTypeList.aspx\" target=\"sysMain\">参数管理</a></li> ");
            }

            return menu.ToString();
        }


        /// <summary>
        /// 是否存在该权限
        /// </summary>
        /// <param name="permission"></param>
        /// <returns></returns>
        private bool IsPermission(string permission)
        {
            if (Session["UserType"] != null)
            {
                int i = int.Parse(Session["UserType"].ToString().Trim());
                if (i == 0)    //0:超级管理员
                {
                    return true;
                }
            }

            if (Session["UserPermission"] != null)
            {
                string str = Session["UserPermission"].ToString();
                if (str.IndexOf(permission) >= 0)
                {
                    return true;
                }
            }

            return false;
        }

        #endregion


    }
}